package com.homework.ch08;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class Test8 {
    public static void main(String[] args) {
        Set<Teacher> t1=new TreeSet<>();
        t1.add(new Teacher(18,"h张三","007"));
        t1.add(new Teacher(19,"a李四","008"));
        t1.add(new Teacher(20,"王五","005"));
        t1.add(new Teacher(26,"h张三","004"));
        t1.add(new Teacher(26,"h张三","001"));
        System.out.println(t1);
        Set<Teacher> t2=new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int name=o1.getName().compareTo(o2.getName());
                if(name!=0){
                    return name;
                }
                int age=o1.getAge()-o2.getAge();
                if(age!=0){
                    return age;
                }
                return o1.getId().compareTo(o2.getId());
            }
        });
        t2.add(new Teacher(18,"h张三","007"));
        t2.add(new Teacher(19,"a李四","008"));
        t2.add(new Teacher(20,"王五","005"));
        t2.add(new Teacher(26,"h张三","004"));
        t2.add(new Teacher(26,"h张三","001"));
        System.out.println(t2);
    }
}
